package uabc.ia.agentelimpieza.vista;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Polygon;
import java.util.Observable;
import java.util.Observer;

import uabc.ia.agentelimpieza.ambiente.Ambiente;
import uabc.ia.agentelimpieza.constantes.Direccion;

public class AspiradoraUI implements Observer {
	private int x;
	private int y;
	private Direccion direccion;
	private int width;
	
	public AspiradoraUI(int x, int y){
		this.x=x;
		this.y=y;
		direccion=Direccion.east;
		width=30;
	}
	
	public void paint(Graphics g) {
		g.setColor(Color.BLUE);
		Point p1;
		Point p2;
		Point p3;
		if(direccion==Direccion.east){
			p1 = new Point(x, y);
			p2 = new Point(x+width,y+(width/2));
			p3 = new Point(x, y+width);
		}
		else
			if(direccion==Direccion.south){
				p1 = new Point(x, y);
				p2 = new Point(x+width,y);
				p3 = new Point(x+(width/2), y+width);
			}
			else
				if(direccion==Direccion.west){
					p1 = new Point(x+width, y);
					p2 = new Point(x+width,y+width);
					p3 = new Point(x, y+(width/2));
				}
				else{
					p1 = new Point(x+(width/2), y);
					p2 = new Point(x+width,y+width);
					p3 = new Point(x, y+width);
				}
		int[] xs = { p1.x, p2.x, p3.x };
		int[] ys = { p1.y, p2.y, p3.y };
		Polygon triangle = new Polygon(xs, ys, xs.length);

		g.fillPolygon(triangle);
		//g.fill3DRect(x, y, width,width , true);
	}
	
	@Override
	public void update(Observable o, Object arg) {
		Ambiente ambiente =(Ambiente)o;
		String accion=(String)arg;
		direccion = ambiente.getDireccion();
		x=(ambiente.getLocacionActual().getX()*100)+25;
		y=(ambiente.getLocacionActual().getY()*100)+25;
		if(accion!=null)
			if(accion.equals("go(home)")&& ambiente.getLocacionActual().getX()==2 &&ambiente.getLocacionActual().getY()==2){
				x=25;
				y=25;
			}
	}
}
